package com.topisv.tms.web.work;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.topisv.tms.entity.AreaGroup;
import com.topisv.tms.entity.ShopSource;
import com.topisv.tms.service.AreaGroupService;
import com.topisv.tms.service.ShopSourceService;
import com.topisv.tms.utils.JsonUtil;

/**
 * 商家仓库_control
 * @author ch
 *
 */
@Controller
@RequestMapping(value = "/warehouse")
public class WarehouseController {
	
	@Autowired
	private AreaGroupService areaGroupService;
	@Autowired
	private ShopSourceService shopSourceService;
	
	private static final Logger logger = LoggerFactory.getLogger(WarehouseController.class);

	/**
	 * 查询仓库
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "ajaxGetWarehouse")
	public String ajaxGetWarehouse(ServletRequest request,HttpServletResponse response) {
		try {
			String customerCode=request.getParameter("customerCode");
			
			List<AreaGroup> warehouseList=null;
			warehouseList=this.areaGroupService.loadByCustomerCode(customerCode);
			
			Map<String,Object> map = new HashMap<String,Object>();
			map.put("warehouseList", warehouseList);
			String json = JsonUtil.getObjectString(map);
			PrintWriter out;
			out = response.getWriter();
			out.print(json);
		} catch (Exception e) {
			
			logger.error("error",e);
		}
		return null;
	}
	
	
	/**
	 * 查询商家店铺
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "ajaxGetShop")
	public String ajaxGetShop(ServletRequest request,HttpServletResponse response) {
		try {
			String customerCode=request.getParameter("customerCode");
			List<ShopSource> shopList=this.shopSourceService.findByCustomerCode(customerCode);
			
			Map<String,Object> map = new HashMap<String,Object>();
			map.put("shopList", shopList);
			String json = JsonUtil.getObjectString(map);
			PrintWriter out;
			out = response.getWriter();
			out.print(json);
		} catch (Exception e) {
			
			logger.error("error",e);
		}
		return null;
	}
	
}
